home *** CD-ROM | disk | FTP | other *** search
- /* Browse.DaFTP
- * Browse AmiNet using DaFTP and AmigaGuide
- * $VER: Browse.daftp 0.15 (31.12.94)
- * By Osma Ahvenlampi and Dan Murrell, Jr.
- */
-
- if ~show(l, 'rexxsupport.library') then
- if ~addlib('rexxsupport.library', 0, -30, 0) then
- exit 50
-
- if ~show(l, 'rexxreqtools.library') then
- if ~addlib('rexxreqtools.library', 0, -30, 0) then
- exit 50
-
- if ~show(l, 'amigaguide.library') then
- if ~addlib('amigaguide.library', 0, -30, 0) then
- exit 50
-
- if ~exists("REXX:Browse.DaFTP") then do
- call rtezrequest("Please copy Browse.DaFTP to REXX: before using!",,"BrowseAminet Error")
- exit 10
- end
-
- /* globals
- */
- dir = "T:BrowseAminet"
- daftp_args = "NOANIMABORT ICONIFIED" /* if Browse.DaFTP needs to start DaFTP, use these args */
-
- /* Initialisation */
- parse arg action ' ' sitename ' ' portname ' ' pubscreen ' ' opt1 ' ' opt2
-
- action = upper( action )
-
- if portname = "" then
- portname = address()
- if portname = "REXX" then
- portname = "daftp"
- if pubscreen = "" then
- pubscreen = "Workbench"
-
- address value portname
- options results
-
- call CreateDir
- call CreatePrefsFile
-
- if open( fdate, "ENVARC:BrowseAminet", 'R' ) then do
- lastdate = readln( fdate )
- temp = readln( fdate )
- parse var temp findsite ' ' use_gzip ' ' maxfind
- call close( fdate )
- end
- else do
- lastdate = 0
- findsite = ""
- use_gzip = 0
- maxfind = 30
- end
-
- if findsite = "" then
- call ChooseFindSite
-
- if use_gzip = "" | use_gzip = "USE_GZIP" then
- use_gzip = 0
-
- if maxfind = "" | maxfind = "MAXFIND" then
- maxfind = 30
-
- say lastdate findsite use_gzip maxfind
-
- /* Possible actions... from first arg:
- * CONNECT - connect to a site
- * LIST - list all files in the ADT_RECENT
- * UPLOAD - send a file
- * FIND - find a file
- * GETFILE - get a file
- * GETMARKED - get all marked files
- * something else - show front page
- */
- if action = "CONNECT" then
- call ConnectAminet
- else if action = "LIST" then
- call ParseRecent dir'/ADT_RECENT' 1
- else if action = "UPLOAD" then
- call UploadFile
- else if action = "FIND" then
- call FindFile
- else if action = "GETFILE" then
- call GetFile
- else if action = "GETMARKED" then
- call GetMarked
- else if action = "SHOWFILE" then
- call ShowFile
- else
- call ShowFrontPage
-
- call Cleanup
- exit 0
-
- /******* main modes ********/
-
- ShowFrontPage: procedure expose portname pubscreen dir
- hotlist = dir'/' || pragma('ID') || '.guide'
- if open(fhotlist, hotlist, 'W') then do
- call writeln(fhotlist, '@database AmiNetBrowser')
- call writeln(fhotlist, '@node "Main" "AmiNet Browser for DaFTP"')
- call writeln(fhotlist, '@{b}AmiNet Browser for DaFTP@{ub}')
- call writeln(fhotlist, 'by Osma Ahvenlampi and Dan Murrell Jr.')
- call writeln(fhotlist, '')
- call writeln(fhotlist, '@{" About BrowseAminet " alink "BrowseAminet.guide/Main"}')
- call writeln(fhotlist, '')
- call writeln(fhotlist, '@{b}AmiNet Sites@{ub}')
-
- if open( fsitelist, "ENVARC:BrowseAminet", 'R' ) then do
- call readln( fsitelist )
- call readln( fsitelist )
- line = readln( fsitelist )
- do while line ~= ""
- colon = lastpos(":", line) + 1
- call writeln(fhotlist, '@{"' line '" rx "Browse.DaFTP CONNECT' substr(line, colon) portname pubscreen'"}')
- line = readln( fsitelist )
- end
- call close( fsitelist )
- end
- else
- exit 10
-
- call writeln(fhotlist, '@endnode')
- call close(fhotlist)
- call shownode( pubscreen, hotlist, 'Main', 0, 0 )
- return
- end
- exit 10
-
- ConnectAminet:
- call InitDaFTP
-
- if use_gzip = 1 then do
- 'GET BIN /pub/aminet/info/adt/ADT_RECENT_7.gz LOCAL' dir'/ADT_RECENT.gz'
-
- address command 'gzip >NIL: -df' dir'/ADT_RECENT.gz'
- if RC ~= 0 then do
- 'DISCONNECT'
- call rtezrequest("Failed to uncompress RECENT file",,"BrowseAminet Error")
- exit 10
- end
- end
- else
- 'GET BIN /pub/aminet/info/adt/ADT_RECENT_7 LOCAL' dir'/ADT_RECENT'
-
- call ParseRecent dir'/ADT_RECENT' 0
- if result ~= "OK" then do
- call rtezrequest(result,,"BrowseAminet Error")
- 'DISCONNECT'
- exit 10
- end
-
- 'DISCONNECT'
-
- call WriteSiteList
-
- return
-
- UploadFile: procedure expose sitename pubscreen portname dir
- filename = rtfilerequest("","","Choose file to be uploaded")
- call rtfreefilebuffer()
- if filename = "" then
- return
- dot = lastpos(".", filename)
- if (dot > 0) then
- readme = left(filename, dot) || 'readme'
- else
- readme = filename'.readme'
- if ~exists( filename ) | ~exists( readme ) then do
- call rtezrequest("Need both file and .readme",,"BrowseAminet Error")
- exit 10
- end
-
- call InitDaFTP
-
- 'CD /pub/aminet/new'
- if RC ~= 0 then do
- call rtezrequest("This site doesn't accept uploads",,"BrowseAminet Error")
- exit 10
- end
-
- 'MPUT' filename readme
-
- return
-
- FindFile: procedure expose sitename pubscreen portname dir lastdate findsite maxfind
- if ~showlist('H','TCP') then do
- call rtezrequest("This function needs TCP: mounted!",,"BrowseAminet Error")
- exit 10
- end
-
- findstr = rtgetstring(,"Please enter search keyword","Find which file?")
- if findstr="" then
- return
- if open( ffindfile, dir'/FINDFILE', 'W' ) then do
- if open( ffind, 'TCP:' || findsite || '/1848', 'W' ) then do
- call writeln( ffind, 'max' maxfind '; ADTfind' findstr '; quit' || d2c(13) )
- do until line = ""
- line = readln( ffind )
- call writeln( ffindfile, line )
- end
- call close( ffind )
- end
- else do
- call rtezrequest("Failed to connect to find server",,"BrowseAminet Error")
- exit 10
- end
-
- call close( ffindfile )
-
- call ParseRecent dir'/FINDFILE' 1
- if result ~= "OK" then do
- call rtezrequest(result,,"BrowseAminet Error")
- exit 10
- end
- return
- end
-
- call rtezrequest("Failure during find attempt",,"BrowseAminet Error")
- exit 10
-
- GetFile: procedure expose sitename pubscreen portname opt1 daftp_args
- call InitDaFTP
- 'SETATTR BATCH 0 PROCESS 1'
- 'GET BIN' opt1
- 'SETATTR PROCESS 0'
- exit 0
-
- GetMarked: procedure expose sitename pubscreen daftp_args portname
- call InitDaFTP
- 'SETATTR BATCH 1 PROCESS 0'
- 'MGET'
- exit 0
-
- ShowFile: procedure expose sitename pubscreen portname opt1 opt2 daftp_args
- call InitDaFTP
- 'SETATTR BATCH 0 PROCESS 0'
- 'GET BIN' opt1 'LOCAL' opt2
- call shownode(pubscreen,opt2,'Main',0,0)
- exit 0
-
- /******* utility procedures ********/
-
- /* read ADT_RECENT and parse it to a .guide
- */
- ParseRecent: procedure expose lastdate sitename dir portname pubscreen
- parse arg recentfile list
-
- newfile = dir'/' || pragma('ID') || '.guide'
-
- if ~open( frecent, recentfile, 'R' ) then
- return "Can't open" recentfile
- if ~open( fnewfile, newfile, 'W' ) then do
- call close( frecent )
- return "Can't create" newfile
- end
-
- line = readln( frecent )
- if line ~= "#adt-v2" then do
- call close( frecent )
- call close( fnewfiles )
- return "Wrong ADT_RECENT version"
- end
-
- call writeln( fnewfile, '@database Browse_RECENT' )
- call writeln( fnewfile, '@node Main "Aminet - using site' sitename'"' )
- call writeln( fnewfile, '@{" Show last week " rx "Browse.DaFTP LIST' sitename portname pubscreen'"} @{" Search for a file " rx "Browse.DaFTP FIND' sitename portname pubscreen'"} @{" Top downloads chart " rx "Browse.DaFTP SHOWFILE' sitename portname pubscreen '/pub/aminet/CHARTS' dir'/CHARTS"}')
- call writeln( fnewfile, '@{" Get marked files " rx "Browse.DaFTP GETMARKED' sitename portname pubscreen'"} @{" Upload file " rx "Browse.DaFTP UPLOAD' sitename portname pubscreen'"} @{" BrowseAminet Help " alink "BrowseAminet.guide/Usage"}')
- call writeln( fnewfile, '' )
-
- do while abbrev( line, "#", 1 )
- line = readln( frecent )
- if list ~= 1 then do
- if abbrev(line,"#amotd",6) then do
- if lastdate < substr(line,8) then do
- 'GET BIN /pub/aminet/info/adt/aminet-motd LOCAL' dir'/motd'
- call shownode(pubscreen,dir'/motd','Main',0,0)
- end
- end
- else if abbrev(line,"#sites",6) then do
- if lastdate < substr(line,8) then
- call ParseSiteList
- end
- end
- end
-
- newdate = lastdate
- newfiles = 0
-
- if list = 1 then
- lastdate = 0
-
- do while line ~= "" & ~abbrev( line, '#' )
- parse var line file.date '@' file.dir '@' file.name '@' file.size '@' a '@' b '@' c '@' file.desc
- if file.date > lastdate then do
- if newdate <= file.date then
- newdate = file.date
- dot = lastpos(".", file.name)
- if (dot > 0) then
- file.readme = left(file.name, dot) || 'readme'
- else
- file.readme = file.name'.readme'
-
- /*name*/ lin = '@{"' left(file.name, 16, ' ') '" rx "Browse.DaFTP GETFILE' sitename portname pubscreen '/pub/aminet/'file.dir'/'file.name'"}'
- /*dir*/ lin = lin left(file.dir, 9, ' ')
- /*size*/ lin = lin '@{"'right(trunc(file.size/1024, 0), 4, ' ') || 'K" rxs "address '''portname''';''SETATTR BATCH 1'';''REVEAL GETLIST 1'';''GET BIN /pub/aminet/'file.dir'/'file.name'''"}'
- /*desc*/ lin = lin '@{"' file.desc '" rx "Browse.DaFTP SHOWFILE' sitename portname pubscreen '/pub/aminet/'file.dir'/'file.readme dir'/'file.readme'"}'
-
- call writeln( fnewfile, lin )
-
- newfiles = 1
- end
-
- line = readln( frecent )
- end
-
- if ~newfiles then
- if list ~= 1 then
- call writeln( fnewfile, ' No new files on' sitename'.' )
- else
- call writeln( fnewfile, ' No files ('sitename').' )
-
- call writeln( fnewfile, '@endnode' )
-
- call close( frecent )
- call close( fnewfile )
-
- call shownode(pubscreen,newfile,'Main',0,0)
-
- lastdate = newdate
-
- return "OK"
-
- /* Make sure DaFTP is running and connected to the correct site
- */
- InitDaFTP: procedure expose portname pubscreen daftp_args sitename
- if ~show( 'P', portname ) then do
- address command 'Run >NIL: DaFTP >NIL:' daftp_args 'PUBSCREEN' pubscreen
- address command 'WaitForPort' portname
- if RC ~= 0 then do
- call rtezrequest("Could not start DaFTP",,"BrowseAminet Error")
- exit 20
- end
- end
-
- /* 'DEACTIVATE' */
- 'SETATTR PROCESS 0 BEEP 0'
- 'REVEAL LOG 0 GETLIST 0 PUTLIST 0 HOTLIST 0'
- 'GETATTR STEM STAT'
- if stat.host ~= sitename then do
- 'DISCONNECT'
- 'SETATTR HOST' sitename 'PORT 21 ANONYMOUS 1 REMOTEDIR /pub/aminet'
- end
- if ~stat.connected then
- 'CONNECT NOSCAN'
-
- return
-
- /* Create a dir for all these files
- */
- CreateDir: procedure expose dir
- if ~exists(dir) then
- call makedir(dir)
- return
-
- /* Cleanup after myself
- */
- Cleanup: procedure expose dir
- address command 'Delete >NIL:' dir 'ALL FORCE QUIET'
- return
-
- /* Read ADT sites file and make a prefs file
- */
- ParseSiteList: procedure expose lastdate dir findsite
- 'GET BIN /pub/aminet/info/adt/sites LOCAL' dir'/sites'
- if open( fsites, dir'/sites', 'R' ) then do
- if open( fsitelist, "ENVARC:BrowseAminet", 'W' ) then do
- call writeln( fsitelist, lastdate )
- call writeln( fsitelist, findsite )
- if readln( fsites ) ~= '#adtrc-v2' then
- return
- do until abbrev( pline, 'ftpsites', 7 )
- pline = readln( fsites )
- end
- sites = 1
- do forever
- line = readln( fsites )
- parse var line area ',' address ',' rest
- writeln( fsitelist, area':'address )
- if right( rest, 1 ) ~= '\' then
- leave
- end
- call close( fsitelist )
- end
- call close( fsites )
- end
- return
-
- /* Update prefs file to current lastdate/findsite/gzip/maxfind
- */
- WriteSiteList: procedure expose lastdate findsite use_gzip maxfind
- tempname = "ENVARC:BrowseAminet-" || pragma('ID')
- if open( fprefs, tempname, 'W' ) then do
- if open( fsitelist, "ENVARC:BrowseAminet", 'R' ) then do
- call readln( fsitelist )
- call writeln( fprefs, lastdate )
- call readln( fsitelist )
- call writeln( fprefs, findsite use_gzip maxfind )
- do until line = ""
- line = readln( fsitelist )
- if line ~= "" then
- call writeln( fprefs, line )
- end
- call close( fsitelist )
- end
- call close( fprefs )
- call delete( "ENVARC:BrowseAminet" )
- call rename( tempname, "ENVARC:BrowseAminet" )
- end
- return
-
- /* Create a simple prefs file for the first run
- */
- CreatePrefsFile: procedure
- if ~exists( "ENVARC:BrowseAminet" ) then
- if open( fsitelist, "ENVARC:BrowseAminet", 'W' ) then do
- call writeln( fsitelist, '0' )
- call writeln( fsitelist, '' )
- call writeln( fsitelist, 'US:ftp.wustl.edu' )
- call writeln( fsitelist, 'US:ftp.netnet.net' )
- call writeln( fsitelist, 'SWEDEN:ftp.luth.se' )
- call writeln( fsitelist, 'GERMANY:ftp.uni-paderborn.de' )
- call writeln( fsitelist, 'UK:ftp.doc.ic.ac.uk' )
- call close( fsitelist )
- end
- return
-
- /* Choose the nearest ADT find server
- */
- ChooseFindSite: procedure expose findsite lastdate
- location = rtezrequest("Please choose the country located nearest to you.","USA|Switzerland|Germany","BrowseAminet configuration")
- if location = 1 then
- findsite = "ftp.wustl.edu"
- else if location = 2 then
- findsite = "amiga.icu.net.ch"
- else if location = 0 then
- findsite = "haegar2.uni-paderborn.de"
- call WriteSiteList
- return
-